//
//  CHNavigationBar.swift
//  Checked
//
//  Created by Shinolr on 1/7/19.
//  Copyright © 2019 shinolr_go. All rights reserved.
//

import UIKit

class CHNavigationBar: UINavigationBar {
    
    let backgroundIdentifier = "_UIBarBackground"
    let visualEffectViewIdentifier = "UIVisualEffectView"
    let visualEffectBackdropView = "_UIVisualEffectBackdropView"
    let contentViewIdentifier = "_UINavigationBarContentView"

    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        for view in subviews {
            print(String(describing: view))
            let viewDescribing = String(describing: view)
            if viewDescribing.contains(backgroundIdentifier) {
//                view.frame = bounds
                var newFrame = view.frame
                newFrame.origin.y = -20
                newFrame.size.height = bounds.size.height - newFrame.origin.y
                view.frame = newFrame
            } else if viewDescribing.contains(visualEffectViewIdentifier) {
                var newFrame = view.frame
                newFrame.origin.y = -20
                newFrame.size.height = bounds.size.height - newFrame.origin.y
                view.frame = newFrame
            } else if viewDescribing.contains(visualEffectBackdropView) {
                var newFrame = view.frame
                newFrame.origin.y = -20
                newFrame.size.height = bounds.size.height - newFrame.origin.y
                view.frame = newFrame
            }
//            else if viewDescribing.contains(contentViewIdentifier) {
//                var newFrame = view.frame
//                newFrame.origin.y = 20
//                newFrame.size.height = bounds.size.height - newFrame.origin.y
//                view.frame = newFrame
//            }
        }
    }
}
